package com.xlong.component.rabbitmq;

import org.springframework.stereotype.Component;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Component
public class RabbitmqConfirmListener implements RabbitTemplate.ConfirmCallback {
	
	/**
     * 回调函数:confirm确认rabbitmq的ack接收情况
     */
    @Override
    public void confirm(CorrelationData correlationData, boolean ack, String s) {
        log.debug("RabbitMQ回调函数，CorrelationData：{},是否成功：{}", correlationData, ack);
        //获取消息ID
        String messageId = correlationData == null ? "" : correlationData.getId();
        String messageReturn = correlationData == null ? "" : correlationData.toString();
        if (ack) {

            log.info("RabbitMQ回调函数返回成功,messageId为： {} ，内容为： {} ", messageId, messageReturn);
        } else {
            log.error("RabbitMQ回调函数返回失败");
        }
    }
}
